/*
 * 
 */
package com.oniontech.stamptour.common.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Debug;
import android.support.v4.app.FragmentActivity;

import com.oniontech.stamptour.ApplicationContext;
import com.oniontech.stamptour.ApplicationManager;
import com.oniontech.stamptour.IntroActivity;
import com.oniontech.stamptour.R;
import com.oniontech.stamptour.common.database.DBContext;
import com.oniontech.stamptour.common.database.DatabaseManager;
import com.oniontech.stamptour.common.lang.LOG;
import com.oniontech.stamptour.module.nfc.StampNfcManager;

// TODO: Auto-generated Javadoc

/**
 * Activity에 추가로 기능을 정의해둔 상위 class.
 *
 * @author limsy
 * @since 2013/02/04
 */
public abstract class DefaultActivity extends FragmentActivity implements
        ApplicationContext, DBContext {

    /**
     * 생성자.
     *
     * @param name 하위클래스 이름.
     */
    public DefaultActivity(String name) {
        TAG = name;
        m_DBMgr = DatabaseManager.getInstance();
//		m_Location = MyLocation.getInstance();
    }

    /*
     * (non-Javadoc)
     *
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        LOG.Log_INFO(TAG, "onCreate() Start~~~");
        super.onCreate(savedInstanceState);

        if (savedInstanceState != null) {
            finish();

            Intent intent = new Intent().setClass(this, IntroActivity.class);
            startActivity(intent);
            return;
        }

        m_AppContext = getApplicationContext();
        m_appMgr = (ApplicationManager) getApplication();

//		System.gc();
//		m_appMgr.initManager();
        int availProc = Runtime.getRuntime().availableProcessors();
        m_lFreeSize = Runtime.getRuntime().totalMemory();
        long free = Runtime.getRuntime().freeMemory();
        long max = Runtime.getRuntime().maxMemory();
        LOG.Log_DEV(TAG, "MemoryInfo availableProcessors : " + availProc
                + ", total : " + m_lFreeSize + ", free : " + free + ", max : "
                + max);
        long nativeHeapSize = Debug.getNativeHeapSize();
        long nativeHeapFreeSize = Debug.getNativeHeapFreeSize();
        long nativeHeapAllocatedSize = Debug.getNativeHeapAllocatedSize();
        LOG.Log_DEV(TAG, "Native MemoryInfo nativeHeapSize : " + nativeHeapSize
                + ", nativeHeapFreeSize : " + nativeHeapFreeSize
                + ", nativeHeapAllocatedSize : " + nativeHeapAllocatedSize);
        LOG.Log_INFO(TAG, "onCreate() End !!!");

    }

    /* (non-Javado* @see android.support.v4.app.FragmentActivity#onSaveInstanceState(android.os.Bundle)
Bundle)
     */
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString("state", "forceKill");
    }

    /**
     * Parses the tel num.
     *
     * @param telNum the tel num
     * @return the string[]
     */
    protected String[] parseTelNum(String telNum) {
        String[] result = telNum.split(",");
        return result;
    }

    /*
     * (non-Javadoc)
     *
     * @see android.app.Activity#onResume()
     */
    @Override
    protected void onResume() {
        LOG.Log_INFO(TAG, "onResume() Start~~~");
        super.onResume();
//		System.gc();
        LOG.Log_INFO(TAG, "onResume() End !!!");

    }

    /*
     * (non-Javadoc)
     *
     * @see android.app.Activity#onPause()
     */
    @Override
    protected void onPause() {
        LOG.Log_INFO(TAG, "onPause() Start~~~");
        super.onPause();
//		System.gc();
        LOG.Log_INFO(TAG, "onPause() End !!!");
    }

    /*
     * (non-Javadoc)
     *
     * @see android.app.Activity#onStop()
     */
    @Override
    protected void onStop() {
        LOG.Log_INFO(TAG, "onStop() Start~~~");
        super.onStop();
//		System.gc();
        LOG.Log_INFO(TAG, "onStop() End !!!");
    }

    /*
     * (non-Javadoc)
     *
     * @see android.app.Activity#onDestroy()
     */
    @Override
    protected void onDestroy() {
        LOG.Log_INFO(TAG, "onDestroy() Start~~~");
        super.onDestroy();
//		System.gc();
        LOG.Log_INFO(TAG, "onDestroy() End !!!");


    }

    /**
     * 새로운 패이지 열기.
     *
     * @param intent 새로열 Page Intent 객체.
     */
    public void startNewDepthPage(Intent intent) {
        startActivity(intent);
        overridePendingTransition(R.anim.slide_in_left, R.anim.zoom_exit);
    }

    /**
     * 현패이지를 삭제후 새로운 패이지 열기.
     *
     * @param intent 새로열 Page Intent객체.
     */
    protected void startFootDepthPage(Intent intent) {
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.zoom_enter, R.anim.slide_out_right);
    }

    /**
     * 현 패이지를 삭제후 새로운 패이지 열기 (With Animation).
     *
     * @param intent 새로열 Page Intent 객체.
     * @param inRes  in Animation Id
     * @param outRes out Animation Id.
     */
    protected void startFootDepthPage(Intent intent, int inRes, int outRes) {
        startActivity(intent);
        finish();
        overridePendingTransition(inRes, outRes);
    }

    /**
     * 현 패이지에 결과값을 전달할수 있는 새로운 패이지 열기.
     *
     * @param intent      새로열 Page Intent 객체.
     * @param requestCode 응값코드 값.
     */
    public void startResultPage(Intent intent, int requestCode) {
        startActivityForResult(intent, requestCode);
        overridePendingTransition(R.anim.slide_in_left, R.anim.zoom_exit);
    }

    /* (non-Javadoc)
     * @see android.support.v4.app.FragmentActivity#onBackPressed()
     */
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        overridePendingTransition(R.anim.zoom_enter, R.anim.slide_out_right);
    }

    /**
     * 하위 클래스 이름을 저장할 변수 선언.
     */
    protected final String TAG;

    /**
     * Database관리 객체 변수.
     */
    protected DatabaseManager m_DBMgr;

    /**
     * Applicaton 관리 객체 변수.
     */
    protected ApplicationManager m_appMgr;

    /**
     * Application Context 객체 변수.
     */
    protected static Context m_AppContext;

    /**
     * The m_l free size.
     */
    protected long m_lFreeSize;

    /** The m_ location. */
//	protected MyLocation m_Location;

    // private ProgressDialog progressBar;
}
